home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
8_13.lha
/
8_13
/
8_13c.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
1KB
|
51 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
/ Match a pattern on the input stream.
/ Use the UNIX System V regcmp(3) routines
/ to do full regular expression matching.
include <pat.h> /* DELETE */
include <ctype.h> /* DELETE */
include <limits.h> /* DELETE */
include <stdlib.h> /* DELETE */
xtern char *regcmp(char* ...);
xtern int regex(char *re, char *subj, char *ret0 ...);
nt pat::match(char *pattern)
// reset base ptr to pt to beginning of buffer
ebp->setbuffering();
// make sure that a full line's worth is available
for (int c = ebp->sgetc();
(c != '\n') && (c != EOF);
c = ebp->sgetc())
ebp->stossc();
int foundnewline = (c == '\n');
// null out the newline
if (foundnewline)
{
ebp->stossc();
ebp->sputbackc(0);
}
// compile the pattern
char *re = regcmp(pattern, (char*)0);
// check the line against the compiled pattern
int goodpattern = regex(re, ebp->base, 0);
// put the newline back
if (foundnewline)
{
ebp->stossc();
ebp->sputbackc('\n');
}
ebp->resetbuffering();
return goodpattern;